﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_Product : System.Web.UI.Page
{

   ProductBus productBus = new ProductBus();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Product product = new Product();


        product.ProductId = txtId.Text.Trim(); ;
        product.ProductName = txtName.Text.Trim();
        product.CategoryId = txtCategoryId.Text.Trim();
        product.Size = Convert.ToInt32(txtSize.Text.Trim());
        product.Color = txtColor.Text.Trim();
        product.Price = Convert.ToInt64(txtPrice.Text.Trim());
        product.Url_img = txtImage.Text.Trim();


        if (product.ProductId.Equals(""))
        {
            ScriptManager.RegisterStartupScript(this, typeof(Page), "FlowerShop.com", "<script>alert('Not empty')</script>", false);
        }
        if (product.ProductName.Equals(""))
        {
            ScriptManager.RegisterStartupScript(this, typeof(Page), "FlowerShop.com", "<script>alert('Not empty')</script>", false);
        }
        string result = productBus.addProduct(product);
        ScriptManager.RegisterStartupScript(this, typeof(Page), "shopflowers.com", "<script>alert('" + result + "')</script>", false);
        Response.Redirect("Product.aspx");

    }



    //protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    //{
    //    ProductBus productBus = new ProductBus();
    //    Session["productedit"] = new List<Product>();

       
    //    if (e.CommandName.CompareTo("edit") == 0)
    //    {
    //        DataTable dt = new DataTable();
           


    //        //Put product detail to session

    //        dt = productBus.GetProductDetailById(e.CommandArgument.ToString());

    //        Session["productedit"] = productBus.GetProductDetailById(dt);

    //        ListBox1.Items.Clear();

    //        for (int i = 0; i < dt.Rows.Count; i++)
    //        {
    //            ListBox1.Items.Add(dt.Rows[i]["ProductId"].ToString() + " - " + dt.Rows[i]["ProductName"].ToString());
    //        }

    //        if (dt.Rows.Count != 0)
    //        {
              

    //            txtId.Text = dt.Rows[0]["ProductId"].ToString();
    //            txtName.Text = dt.Rows[0]["ProductName"].ToString();
    //            txtCategoryId.Text = dt.Rows[0]["CategoryId"].ToString();
    //            txtSize.Text = string.Format("{0:0}", dt.Rows[0]["Size"].ToString());
    //            txtColor.Text = dt.Rows[0]["Color"].ToString();
    //            txtPrice.Text = string.Format("{0:0,0.0}", dt.Rows[0]["Price"].ToString());
    //            txtImage.Text = dt.Rows[0]["Image"].ToString();


    //        }

    //    }
    //}
    
}
